package com.syt.user.api;

import com.syt.model.user.UserInfo;
import com.syt.result.Result;
import com.syt.user.service.UserInfoService;
import com.syt.utils.AuthContextHolder;
import com.syt.vo.user.LoginVo;
import com.syt.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author: xxx
 * @Date: 2023/2/20 22:01
 * @Description: 用户api
 */
@Api(tags = "用户api接口")
@RestController
@RequestMapping("/api/user")
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "获取用户id的信息")
    @GetMapping("/auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        UserInfo userInfo = userInfoService.getById(userId);
        return Result.ok(userInfo);
    }

    @ApiOperation(value = "用户认证接口")
    @PostMapping("/auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request){
        userInfoService.userAuth(AuthContextHolder.getUserId(request), userAuthVo);
        return Result.ok();
    }



    @ApiOperation(value = "根据用户手机号码登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo){
        Map<String,Object> userInfo= userInfoService.loginUser(loginVo);
        return Result.ok(userInfo);
    }

}
